package org.example.skytool.commom;

import org.example.dao.dto.user.UserDto;
import org.example.exception.JwErrorException;
import org.example.service.oaa.OaaServiceImpl;
import org.example.skytool.security.ThreadLocalUtil;
import org.example.skytool.redis.RedisConstants;
import org.example.skytool.redis.RedisUtils;
import org.example.utils.oaa.RedisOaaService;
import org.example.utils.user.RedisUserService;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class ContextUtil {

    @Resource
    private ThreadLocalUtil threadLocalUtil;

    @Resource
    private RedisUtils redisUtils;

    @Resource
    private RedisUserService redisUserService;

    /**
     * 获取当前操作的用户id
     */
    public Long getId() {
        String userId = threadLocalUtil.getId();
        if (userId == null) {
            return 0L;
        }
        return Long.valueOf(userId);
    }

    /**
     * 获取当前操作的用户cookie
     */
    public String getCookie() {
        String userId = threadLocalUtil.getId();
        return redisUserService.getCacheCookie(userId);
    }

    /**
     * 获取当前操作的用户
     */
    public UserDto getLoginUser() {
        String userId = threadLocalUtil.getId();
        return redisUserService.getUserDto(userId);
    }

}
